/**
 * <pre>
 * Title: 		MailListUtil.java
 * Project: 	AgentPortal_1.13.x
 * Author:		linriqing
 * Create:	 	2009-3-24 下午04:11:17
 * Copyright: 	Copyright (c) 2009
 * Company:		Shenzhen Helper
 * <pre>
 */
package com.hengpeng.itfin.domain;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.hengpeng.common.mail.Contact;
import com.hengpeng.common.mail.MailMessage;
import com.hengpeng.common.mail.Postman;
import com.hengpeng.common.mail.SMTPConfig;
import com.hengpeng.itfin.common.SystemConfigUtil;

/**
 * <pre>
 * 邮件列表工具
 * </pre>
 * @author linriqing
 * @version 1.0, 2009-3-24
 */
public class MailListUtil
{
	private final static Log logger = LogFactory.getLog(MailListUtil.class);

	/**
	 * 系统参数名-SMTP登录名
	 */
	public final static String SYSTEMCONFIG_PARANAME_SMTP_LOGINID = "mail.from";

	/**
	 * 系统参数名-SMTP登录密码
	 */
	public final static String SYSTEMCONFIG_PARANAME_SMTP_LOGINPWD = "mail.from.password";

	/**
	 * 回复地址
	 */
	public final static String SYSTEMCONFIG_PARANAME_SMTP_MAILFROM = "mail.from";

	/**
	 * 系统参数名-SMTP主机名
	 */
	public final static String SYSTEMCONFIG_PARANAME_SMTP_SERVER = "mail.smtp.host";

	/**
	 * <pre>
	 * 发送邮件到邮件列表
	 * </pre>
	 * @param list 邮件列表
	 * @param subject 主题
	 * @param content 内容
	 */
	public static void doSendMailList(List<Contact> list, String subject, String content)
	{
		SMTPConfig smtp = new SMTPConfig(SystemConfigUtil.getConfigValue(
				MailListUtil.SYSTEMCONFIG_PARANAME_SMTP_LOGINID), SystemConfigUtil.getConfigValue(
				MailListUtil.SYSTEMCONFIG_PARANAME_SMTP_LOGINPWD), SystemConfigUtil.getConfigValue(
				MailListUtil.SYSTEMCONFIG_PARANAME_SMTP_SERVER), SystemConfigUtil.getConfigValue(
				MailListUtil.SYSTEMCONFIG_PARANAME_SMTP_MAILFROM));

		if (list.size() > 0)
		{
			Postman postman = new Postman(smtp);
			MailMessage message = new MailMessage();
			message.setContent(content);
			message.setSubject(subject);
			try
			{
				postman.send(message, list);
			}
			catch (Exception e)
			{
				MailListUtil.logger.error("事件通知邮件列表发送邮件通知失败...", e);
			}
		}
	}
}
